package com.gongyibao.gbase.controller;

import com.gongyibao.gbase.common.BaseController;
import com.gongyibao.gbase.common.BaseResult;
import com.gongyibao.gbase.entity.TDepartment;
import com.gongyibao.gbase.service.TDepartmentService;
import com.gongyibao.gbase.utils.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/api/dep/")
public class DepartmentController extends BaseController {

    @Resource
    TDepartmentService departmentService;

    @GetMapping("getDepartmentById")
    public BaseResult<TDepartment> getDepartmentById(Integer id) {
        TDepartment department = departmentService.getDepartmentById(id);
        return success(department);
    }

    @PostMapping("insert")
    public BaseResult<Boolean> inserTDepartment(@RequestBody TDepartment user) {
        Boolean flag = departmentService.insertDepartment(user);
        return success(flag);
    }

    @PostMapping("insertDepartment")
    public BaseResult<Boolean> inserTDepartment() {

        TDepartment department = getDepartmentInstance();

        Boolean flag = departmentService.insertDepartment(department);
        return success(flag);
    }

    @PostMapping("updateDepartment")
    public BaseResult<Boolean> updateUser(@RequestBody TDepartment user) {

        Boolean flag = departmentService.updateDepartment(user);
        return success(flag);
    }

    @PostMapping("delDepartment")
    public BaseResult<Boolean> updateUser(Integer id) {

        Boolean flag = departmentService.delDepartment(id);
        return success(flag);
    }


    private TDepartment getDepartmentInstance() {
        TDepartment department = new TDepartment();
        department.setId(0);
        department.setDepName("Department2");
        department.setDepCode("2");
        department.setStatus("1");
        department.setOrder(2);
        return department;
    }

    @PostMapping("getRW")
    public BaseResult<Boolean> getRW() {

        HashMap map = departmentService.getRW();
        System.out.println(map.toString());
        return success(true);
    }

}
